<%= form_for(@photoalbum, :multipart => true) do |f| %>
  <% if @photoalbum.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@photoalbum.errors.count, "error") %> prohibited this photoalbum from being saved:</h2>

      <ul>
      <% @photoalbum.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </div>
<%=link_to "Add More", "#", :id => "add_more"%>
  <div class="newPaperclipFiles" id="new_files_div">

    <%= f.fields_for :photos do |photo| %>

      <% if photo.object.new_record? %>
        <%= photo.file_field :image %>
        Tags <%= photo.text_field :tags %>
    <% end %><br />

    <% end %> 

  </div>


  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>
<script>
  var image_count = 1;
  $(function() {
    $("#add_more").click(function(e) {
      e.preventDefault();
      $("#new_files_div").append(
      $("<input id='photoalbum_photos_attributes_" + image_count + "_image' name='photoalbum[photos_attributes][" + image_count +"][image]' type='file'/>" +
       " Tags " +
       "<input id='photoalbum_photos_attributes_" + image_count + "_tags' name='photoalbum[photos_attributes][" + image_count + "][tags]' size='30' type='text'/><br/>")
        );
        image_count+=1;
    });
  });
</script>

